using System;
using System.Collections.Generic;
using System.Text;
using Sixeyed.CacheAdapter.Interfaces;
using System.Xml.Serialization;
using xml = System.Xml;
using System.ComponentModel;

namespace Sixeyed.CacheAdapter.NCacheExpressProvider
{
    /// <summary>
    /// Cache instance configuration for NCache Express provider
    /// </summary>
    /// <remarks>
    /// XmlSerializer does not handle TimeSpan objects correctly, so DefaultLifespan is not serialized
    /// and a dummy string property is used to record the serialized value
    /// </remarks>
    [Serializable]
    [XmlRoot(ElementName = "NCacheExpressProviderConfiguration", Namespace = "http://schemas.sixeyed.com/CacheAdapter/2009")]
    public class NCacheExpressProviderConfiguration : ICacheProviderConfiguration
    {
        private string _cacheId;
        private TimeSpan _defaultLifespan = TimeSpan.Zero;

        /// <summary>
        /// Gets/sets the ID of the NCache store
        /// </summary>
        [Description("The ID of the NCache Express store to access")]
        [XmlElement(ElementName = "cacheId")]
        public string CacheId
        {
            get { return this._cacheId; }
            set { this._cacheId = value; }
        }

        /// <summary>
        /// Gets/sets the XML representation of the default expiration lifespan for the store
        /// </summary>
        /// <remarks>
        /// Not seen by consumers of ICacheProviderConfiguration, used for serialization only
        /// </remarks>
        [Browsable(false)]        
        [XmlElement(ElementName = "defaultLifespan")]
        public string DefaultLifespanXml
        {
            get { return xml.XmlConvert.ToString(this._defaultLifespan); }
            set { this._defaultLifespan = xml.XmlConvert.ToTimeSpan(value); }
        }

        /// <summary>
        /// Gets/sets the the default expiration lifespan for the store
        /// </summary>
        /// <remarks>
        /// Seen by consumers of ICacheProviderConfiguration, not used for serialization
        /// </remarks>
        [Description("The default expiration timeout of objects added to the cache. Leave as zero - 00:00:00 - to have no default expiration timeout.")]
        [XmlIgnore]
        public TimeSpan DefaultLifespan
        {
            get { return this._defaultLifespan; }
            set { this._defaultLifespan = value; }
        }       
    }
}